Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Version 4 #6

Merged
merged 21 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d6edb20
update package versions
Garados007 Jan 10, 2021
667d758
move the logic from HttpHeaderPostParser to the HttpRequestHeader its…
Garados007 Jan 10, 2021
069176c
Merge branch 'main' into develop
Garados007 Jan 17, 2021
8ba3958
remove the ini loading for the config. This removes the dependency to…
Garados007 Feb 7, 2022
01958f0
remove reading functionality from data sources
Garados007 Feb 7, 2022
a970911
change the range behaviour of the datasource classes
Garados007 Feb 7, 2022
bff9f0d
Merge branch 'main' into develop
Garados007 May 7, 2022
426b47f
fix version
Garados007 May 7, 2022
a735c2d
Merge branch 'main' into develop
Garados007 May 31, 2022
abd920a
Merge branch 'refactor/server-config' into version-4
Garados007 May 31, 2022
b0dd306
Merge branch 'refactor/readonly-datasources' into version-4
Garados007 May 31, 2022
a33706e
fix dependency and test issues
Garados007 May 31, 2022
3fb4f35
update test cases and deprecate Api system in favour of the builder s…
Garados007 May 31, 2022
e249fde
include the readme as doc
Garados007 May 31, 2022
8732260
move test and example projects in their folders
Garados007 May 31, 2022
f5cfac7
deprecate standard document loader
Garados007 May 31, 2022
eb99253
update example
Garados007 May 31, 2022
9398835
update examples
Garados007 May 31, 2022
342af70
bump version to 4.0.0, add missing dependency
Garados007 Sep 11, 2022
a3643a1
Add gitattributes file
Garados007 Feb 18, 2024
a0d865b
Add dotnet 8 builds and remove deprecated dotnet versions
Garados007 Feb 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Default setting
* auto

# Do nothing
*.sln -text
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: |
8.0
6.0.102
3.1.101
- name: Install dependencies
run: dotnet restore
- name: Build
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ jobs:

steps:
- uses: actions/checkout@v2

- name: Init git submodules
run: git submodule init && git submodule update

- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.102
dotnet-version: '8.0'
- name: Install dependencies
run: dotnet restore

- name: Publish MaxLib.WebServer NuGet
uses: brandedoutcast/[email protected]
with:
Expand Down
22 changes: 0 additions & 22 deletions MaxLib.WebServer.Test/MaxLib.WebServer.Test.csproj

This file was deleted.

4 changes: 2 additions & 2 deletions MaxLib.WebServer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ VisualStudioVersion = 16.0.30717.126
MinimumVisualStudioVersion = 15.0.26124.0
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MaxLib.WebServer", "MaxLib.WebServer\MaxLib.WebServer.csproj", "{595DB1BF-246A-4A42-99EB-5DAB7709E21E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MaxLib.WebServer.Test", "MaxLib.WebServer.Test\MaxLib.WebServer.Test.csproj", "{60225D92-5742-4BC0-A3A5-206123F2129D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MaxLib.WebServer.Test", "tests\MaxLib.WebServer.Test\MaxLib.WebServer.Test.csproj", "{60225D92-5742-4BC0-A3A5-206123F2129D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MaxLib.WebServer.Example", "example\MaxLib.WebServer.Example\MaxLib.WebServer.Example.csproj", "{6616448A-1AD7-4897-9124-F1560FB12461}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Example", "Example", "{39740782-6F07-470C-92B8-C0A07A5C0DFB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MaxLib.WebServer.WebSocket.Echo", "MaxLib.WebServer.WebSocket.Echo\MaxLib.WebServer.WebSocket.Echo.csproj", "{01C302FF-8E99-4D54-8234-D4BA59862176}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MaxLib.WebServer.WebSocket.Echo", "example\MaxLib.WebServer.WebSocket.Echo\MaxLib.WebServer.WebSocket.Echo.csproj", "{01C302FF-8E99-4D54-8234-D4BA59862176}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{29467014-E04B-477A-82B7-16A3BAE7B5A6}"
ProjectSection(SolutionItems) = preProject
Expand Down
1 change: 1 addition & 0 deletions MaxLib.WebServer/Api/ApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace MaxLib.WebServer.Api
{
[Obsolete("The ApiService and the RestApiService classes are no longer maintained and will be removed in a future update. Use the Builder system instead.")]
public abstract class ApiService : WebService
{
public ApiService(params string[] endpoint)
Expand Down
1 change: 1 addition & 0 deletions MaxLib.WebServer/Api/Rest/ApiGetRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace MaxLib.WebServer.Api.Rest
{
[Obsolete("The ApiService and the RestApiService classes are no longer maintained and will be removed in a future update. Use the Builder system instead.")]
public abstract class ApiGetRule : ApiRule
{
private string? key;
Expand Down
1 change: 1 addition & 0 deletions MaxLib.WebServer/Api/Rest/ApiLocationRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace MaxLib.WebServer.Api.Rest
{
[Obsolete("The ApiService and the RestApiService classes are no longer maintained and will be removed in a future update. Use the Builder system instead.")]
public abstract class ApiLocationRule : ApiRule
{
private int index = 0;
Expand Down
3 changes: 3 additions & 0 deletions MaxLib.WebServer/Api/Rest/ApiRule.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#nullable enable

using System;

namespace MaxLib.WebServer.Api.Rest
{
[Obsolete("The ApiService and the RestApiService classes are no longer maintained and will be removed in a future update. Use the Builder system instead.")]
public abstract class ApiRule
{
public bool Required { get; set; } = true;
Expand Down
1 change: 1 addition & 0 deletions MaxLib.WebServer/Api/Rest/ApiRuleFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace MaxLib.WebServer.Api.Rest
{
[Obsolete("The ApiService and the RestApiService classes are no longer maintained and will be removed in a future update. Use the Builder system instead.")]
public class ApiRuleFactory
{
public class HostRule : ApiRule
Expand Down
1 change: 1 addition & 0 deletions MaxLib.WebServer/Api/Rest/RestActionEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace MaxLib.WebServer.Api.Rest
{
[Obsolete("The ApiService and the RestApiService classes are no longer maintained and will be removed in a future update. Use the Builder system instead.")]
public class RestActionEndpoint : RestEndpoint
{
public Func<Dictionary<string, object?>, Task<HttpDataSource?>> HandleRequest { get; set; }
Expand Down
1 change: 1 addition & 0 deletions MaxLib.WebServer/Api/Rest/RestApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace MaxLib.WebServer.Api.Rest
{
[Obsolete("The ApiService and the RestApiService classes are no longer maintained and will be removed in a future update. Use the Builder system instead.")]
public class RestApiService : ApiService
{
public List<RestEndpoint> RestEndpoints { get; } = new List<RestEndpoint>();
Expand Down
1 change: 1 addition & 0 deletions MaxLib.WebServer/Api/Rest/RestEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace MaxLib.WebServer.Api.Rest
{
[Obsolete("The ApiService and the RestApiService classes are no longer maintained and will be removed in a future update. Use the Builder system instead.")]
public class RestEndpoint
{
readonly private ApiRuleFactory.GroupRule rules = new ApiRuleFactory.GroupRule();
Expand Down
1 change: 1 addition & 0 deletions MaxLib.WebServer/Api/Rest/RestQueryArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace MaxLib.WebServer.Api.Rest
{
[Obsolete("The ApiService and the RestApiService classes are no longer maintained and will be removed in a future update. Use the Builder system instead.")]
public class RestQueryArgs
{
public string[] Location { get; }
Expand Down
129 changes: 15 additions & 114 deletions MaxLib.WebServer/Chunked/HttpChunkedStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,53 +23,33 @@ public HttpChunkedStream(Stream baseStream, int readBufferLength = 0x8000)

public int ReadBufferLength { get; }

[Obsolete]
public override bool CanAcceptData => BaseStream.CanWrite;

public override bool CanProvideData => BaseStream.CanRead;

public override long? Length() => null;

public override void Dispose()
{
BaseStream.Dispose();
}

protected override async Task<long> WriteStreamInternal(Stream stream, long start, long? stop)
protected override async Task<long> WriteStreamInternal(Stream stream)
{
long total = 0;
int readed;
byte[] buffer = new byte[ReadBufferLength];
do
{
readed = await BaseStream.ReadAsync(
buffer,
0,
(int)Math.Min(buffer.Length, start - total)
).ConfigureAwait(false);
total += readed;
}
while (total < start && readed > 0);
if (readed == 0 && start > 0)
return 0;
int read;
Memory<byte> buffer = new byte[ReadBufferLength];
var ascii = Encoding.ASCII;
var nl = ascii.GetBytes("\r\n");
ReadOnlyMemory<byte> nl = ascii.GetBytes("\r\n");
do
{
var read = stop == null
? buffer.Length
: (int)Math.Min(buffer.Length, stop.Value - total);
readed = await BaseStream.ReadAsync(buffer, 0, read).ConfigureAwait(false);
if (readed <= 0)
return total - start;
var length = ascii.GetBytes(readed.ToString("X"));
read = await BaseStream.ReadAsync(buffer).ConfigureAwait(false);
if (read <= 0)
return total;
ReadOnlyMemory<byte> length = ascii.GetBytes(read.ToString("X"));
try
{
await stream.WriteAsync(length, 0, length.Length).ConfigureAwait(false);
await stream.WriteAsync(nl, 0, nl.Length).ConfigureAwait(false);
await stream.WriteAsync(buffer, 0, readed).ConfigureAwait(false);
await stream.WriteAsync(nl, 0, nl.Length).ConfigureAwait(false);
total += readed;
await stream.WriteAsync(length).ConfigureAwait(false);
await stream.WriteAsync(nl).ConfigureAwait(false);
await stream.WriteAsync(buffer[0..read]).ConfigureAwait(false);
await stream.WriteAsync(nl).ConfigureAwait(false);
total += read;
await stream.FlushAsync().ConfigureAwait(false);
}
catch (IOException)
Expand All @@ -78,87 +58,8 @@ protected override async Task<long> WriteStreamInternal(Stream stream, long star
return total;
}
}
while (readed > 0);
return total - start;
}

[Obsolete]
protected override async Task<long> ReadStreamInternal(Stream stream, long? length)
{
long total = 0;
int readed, numberLength;
var ascii = Encoding.ASCII;
var buffer = new byte[0x10000];
while (true)
{
try { numberLength = await ReadNumber(stream, buffer).ConfigureAwait(false); }
catch (IOException)
{
WebServerLog.Add(ServerLogType.Information, GetType(), "read", "connection closed");
return total;
}
if (numberLength == 0)
return total;
var numberString = ascii.GetString(buffer, 0, numberLength);
if (!long.TryParse(numberString,
NumberStyles.HexNumber,
CultureInfo.InvariantCulture.NumberFormat,
out long number) || number < 0)
{
WebServerLog.Add(ServerLogType.Information, GetType(), "read", "invalid number of bytes indicator");
return total;
}
while (number > 0)
{
try { readed = await stream.ReadAsync(buffer, 0, (int)Math.Min(number, buffer.Length)).ConfigureAwait(false); }
catch (IOException)
{
WebServerLog.Add(ServerLogType.Information, GetType(), "read", "connection closed");
return total;
}
if (readed == 0)
{
WebServerLog.Add(ServerLogType.Information, GetType(), "read", "could not read the block completly");
return total;
}
await BaseStream.WriteAsync(buffer, 0, readed).ConfigureAwait(false);
total += readed;
number -= readed;
}
try
{
readed = await stream.ReadAsync(buffer, 0, 1).ConfigureAwait(false);
if (readed > 0 && buffer[0] == '\r')
readed = await stream.ReadAsync(buffer, 0, 1).ConfigureAwait(false);
if (readed == 0)
return total;
}
catch (IOException)
{
WebServerLog.Add(ServerLogType.Information, GetType(), "read", "connection closed");
return total;
}
}
}

private async Task<int> ReadNumber(Stream stream, byte[] buffer)
{
int offset = 0;
var byteBuffer = new byte[1];
while (true)
{
int readed = await stream.ReadAsync(byteBuffer, 0, 1).ConfigureAwait(false);
if (readed == 0)
return offset;
if (byteBuffer[0] == '\r' || byteBuffer[0] == '\n')
{
if (byteBuffer[0] == '\r')
await stream.ReadAsync(byteBuffer, 0, 1).ConfigureAwait(false);
return offset;
}
buffer[offset] = byteBuffer[0];
offset++;
}
while (read > 0);
return total;
}
}
}
Loading
Loading