Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 0 additions & 3 deletions API/GenHTTP.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
<PackageTags>GenHTTP HTTP Embedded Webserver Website Server Library C# Standard API</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>

<!-- remove this line after Fleck has been removed -->
<NoWarn>CS1591,CS1587,CS1572,CS1573,CS0612,CS0618</NoWarn>

</PropertyGroup>

<ItemGroup>
Expand Down
9 changes: 1 addition & 8 deletions API/Protocol/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ public enum Connection
/// the configured response and will close the connection after the response content
/// has been sent.
/// </summary>
Upgrade,

/// <summary>
/// The connection is surrendered to the user logic and the server will not attempt
/// to close or change it in any way.
/// </summary>
[Obsolete("Required to allow Fleck to write their own response. Will be removed in GenHTTP 11.")]
UpgradeAndSurrender
Upgrade

}
12 changes: 0 additions & 12 deletions API/Protocol/IRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,6 @@ public interface IRequest : IDisposable
/// <returns>The newly created response</returns>
IResponseBuilder Respond();

/// <summary>
/// Upgrades the connection of the client, causing the underlying socket and streams
/// to be exposed and to be used by another protocol, such as a websocket handler.
/// </summary>
/// <returns>The upgrade information to use</returns>
/// <remarks>
/// After upgrading a connection, the server will surrender this socket and stream to your logic
/// to no further interaction is done by the framework with the client and is up to
/// your logic.
/// </remarks>
UpgradeInfo Upgrade();

#endregion

#region General Infrastructure
Expand Down
6 changes: 0 additions & 6 deletions API/Protocol/IResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ public interface IResponse : IDisposable
/// </summary>
Connection Connection { get; set; }

/// <summary>
/// Specifies whether the server should surrender the connection to the user code.
/// </summary>
[Obsolete("Replaced by ConnectionHandling.Upgrade. This property will be removed in GenHTTP 11.")]
public bool Upgraded { get; }

#endregion

#region Headers
Expand Down
12 changes: 0 additions & 12 deletions API/Protocol/UpgradeInfo.cs

This file was deleted.

3 changes: 0 additions & 3 deletions Adapters/AspNetCore/GenHTTP.Adapters.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

<Authors>Andreas Nägeli, Tanzim Hossain Romel</Authors>

<!-- remove this line after Fleck has been removed -->
<NoWarn>CS1591,CS1587,CS1572,CS1573,CS0612,CS0618</NoWarn>

</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions Adapters/AspNetCore/Types/Request.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ public IResponseBuilder Respond()
return _responseBuilder;
}

public UpgradeInfo Upgrade() => throw new NotSupportedException("Web sockets are not supported by the Kestrel server implementation");

internal void Configure(IServer server, HttpContext context)
{
var request = context.Request;
Expand Down
6 changes: 3 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<ImplicitUsings>enable</ImplicitUsings>

<AssemblyVersion>10.5.0.0</AssemblyVersion>
<FileVersion>10.5.0.0</FileVersion>
<Version>10.5.0</Version>
<AssemblyVersion>11.0.0.0</AssemblyVersion>
<FileVersion>11.0.0.0</FileVersion>
<Version>11.0.0</Version>

<Authors>Andreas Nägeli</Authors>

Expand Down
3 changes: 0 additions & 3 deletions Engine/Internal/GenHTTP.Engine.Internal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
<PackageTags>GenHTTP HTTP Embedded Webserver Server Library C# Standard Engine</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>

<!-- remove this line after Fleck has been removed -->
<NoWarn>CS1591,CS1587,CS1572,CS1573,CS0612,CS0618</NoWarn>

</PropertyGroup>

<ItemGroup>
Expand Down
60 changes: 26 additions & 34 deletions Engine/Internal/Protocol/ClientHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
using System.IO.Pipelines;
using System.Net.Sockets;
using System.Security.Cryptography.X509Certificates;

using GenHTTP.Api.Infrastructure;
using GenHTTP.Api.Protocol;

using GenHTTP.Engine.Internal.Protocol.Parser;
using GenHTTP.Engine.Internal.Utilities;
using GenHTTP.Engine.Shared.Infrastructure;
using GenHTTP.Engine.Shared.Types;

using Microsoft.Extensions.ObjectPool;

using StringContent = GenHTTP.Modules.IO.Strings.StringContent;

namespace GenHTTP.Engine.Internal.Protocol;
Expand Down Expand Up @@ -68,46 +72,41 @@

internal async ValueTask Run()
{
var status = Api.Protocol.Connection.Close;

try
{
status = await HandlePipe(PipeReader.Create(Stream, ReaderOptions)).ConfigureAwait(false);
await HandlePipe(PipeReader.Create(Stream, ReaderOptions)).ConfigureAwait(false);
}
catch (Exception e)
{
Server.Companion?.OnServerError(ServerErrorScope.ClientConnection, Connection.GetAddress(), e);
}
finally
{
if (status != Api.Protocol.Connection.UpgradeAndSurrender)
try
{
try
{
await Stream.DisposeAsync();
}
catch (Exception e)
{
Server.Companion?.OnServerError(ServerErrorScope.ClientConnection, Connection.GetAddress(), e);
}
await Stream.DisposeAsync();
}
catch (Exception e)
{
Server.Companion?.OnServerError(ServerErrorScope.ClientConnection, Connection.GetAddress(), e);
}

try
{
Connection.Shutdown(SocketShutdown.Both);
await Connection.DisconnectAsync(false);
Connection.Close();
try

Check warning on line 94 in Engine/Internal/Protocol/ClientHandler.cs

View workflow job for this annotation

GitHub Actions / Test & Coverage

Combine this 'try' with the one starting on line 85. (https://rules.sonarsource.com/csharp/RSPEC-2327)

Check warning on line 94 in Engine/Internal/Protocol/ClientHandler.cs

View workflow job for this annotation

GitHub Actions / Test & Coverage

Combine this 'try' with the one starting on line 85. (https://rules.sonarsource.com/csharp/RSPEC-2327)

Check warning on line 94 in Engine/Internal/Protocol/ClientHandler.cs

View workflow job for this annotation

GitHub Actions / Test & Coverage

Combine this 'try' with the one starting on line 85. (https://rules.sonarsource.com/csharp/RSPEC-2327)

Check warning on line 94 in Engine/Internal/Protocol/ClientHandler.cs

View workflow job for this annotation

GitHub Actions / Test & Coverage

Combine this 'try' with the one starting on line 85. (https://rules.sonarsource.com/csharp/RSPEC-2327)

Check warning on line 94 in Engine/Internal/Protocol/ClientHandler.cs

View workflow job for this annotation

GitHub Actions / Test & Coverage

Combine this 'try' with the one starting on line 85. (https://rules.sonarsource.com/csharp/RSPEC-2327)

Check warning on line 94 in Engine/Internal/Protocol/ClientHandler.cs

View workflow job for this annotation

GitHub Actions / Test & Coverage

Combine this 'try' with the one starting on line 85. (https://rules.sonarsource.com/csharp/RSPEC-2327)
{
Connection.Shutdown(SocketShutdown.Both);
await Connection.DisconnectAsync(false);
Connection.Close();

Connection.Dispose();
}
catch (Exception e)
{
Server.Companion?.OnServerError(ServerErrorScope.ClientConnection, Connection.GetAddress(), e);
}
Connection.Dispose();
}
catch (Exception e)
{
Server.Companion?.OnServerError(ServerErrorScope.ClientConnection, Connection.GetAddress(), e);
}
}
}

private async ValueTask<Connection> HandlePipe(PipeReader reader)
private async ValueTask HandlePipe(PipeReader reader)
{
var context = ContextPool.Get();

Expand Down Expand Up @@ -139,9 +138,9 @@

var status = await HandleRequest(context.Request, !buffer.ReadRequired);

if (status is Api.Protocol.Connection.Close or Api.Protocol.Connection.UpgradeAndSurrender)
if (status is Api.Protocol.Connection.Close)
{
return status;
return;
}
}
}
Expand All @@ -164,23 +163,16 @@

await reader.CompleteAsync();
}

return Api.Protocol.Connection.Close;
}

private async ValueTask<Connection> HandleRequest(Request request, bool dataRemaining)
{
request.SetConnection(Server, Connection, Stream, EndPoint, Connection.GetAddress(), ClientCertificate);
request.SetConnection(Server, EndPoint, Connection.GetAddress(), ClientCertificate);

var keepAliveRequested = request["Connection"]?.Equals("Keep-Alive", StringComparison.InvariantCultureIgnoreCase) ?? request.ProtocolType == HttpProtocol.Http11;

var response = await Server.Handler.HandleAsync(request) ?? throw new InvalidOperationException("The root request handler did not return a response");

if (response.Connection == Api.Protocol.Connection.UpgradeAndSurrender)
{
return Api.Protocol.Connection.UpgradeAndSurrender;
}

var closeRequested = response.Connection is Api.Protocol.Connection.Close or Api.Protocol.Connection.Upgrade;

var active = await ResponseHandler.Handle(request, response, request.ProtocolType, keepAliveRequested && !closeRequested, dataRemaining);
Expand Down
20 changes: 1 addition & 19 deletions Engine/Internal/Protocol/Request.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography.X509Certificates;

using GenHTTP.Api.Infrastructure;
using GenHTTP.Api.Protocol;
using GenHTTP.Api.Routing;

using GenHTTP.Engine.Internal.Utilities;
using GenHTTP.Engine.Shared.Types;

using CookieCollection = GenHTTP.Engine.Shared.Types.CookieCollection;
Expand All @@ -28,9 +25,6 @@ internal sealed class Request : IRequest
private IClientConnection? _clientConnection;
private IClientConnection? _localClient;

private Socket? _socket;
private Stream? _stream;

private FlexibleRequestMethod? _method;
private RoutingTarget? _target;

Expand Down Expand Up @@ -130,27 +124,15 @@ public IResponseBuilder Respond()
return _responseBuilder;
}

public UpgradeInfo Upgrade()
{
if (_socket == null || _stream == null)
{
throw new InvalidOperationException("Request is not initialized yet");
}

return new(_socket, _stream, new Response { Connection = Connection.UpgradeAndSurrender});
}

public bool ContainsMultipleHeaders(string key) => _headers.ContainsMultiple(key);

#endregion

#region Parsing

internal void SetConnection(IServer server, Socket connection, PoolBufferedStream stream, IEndPoint endPoint, IPAddress? address, X509Certificate? clientCertificate)
internal void SetConnection(IServer server, IEndPoint endPoint, IPAddress? address, X509Certificate? clientCertificate)
{
_server = server;
_socket = connection;
_stream = stream;
_endPoint = endPoint;

var protocol = _endPoint.Secure ? ClientProtocol.Https : ClientProtocol.Http;
Expand Down
3 changes: 0 additions & 3 deletions Engine/Shared/GenHTTP.Engine.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
<PackageTags>GenHTTP Engine</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>

<!-- remove this line after Fleck has been removed -->
<NoWarn>CS1591,CS1587,CS1572,CS1573,CS0612,CS0618</NoWarn>

</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions Engine/Shared/Types/Response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public Response()

public Connection Connection { get; set; }

public bool Upgraded => Connection == Connection.UpgradeAndSurrender;

public DateTime? Expires { get; set; }

public DateTime? Modified { get; set; }
Expand Down
3 changes: 0 additions & 3 deletions Modules/Compression/GenHTTP.Modules.Compression.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
<PackageTags>GenHTTP HTTP Webserver C# Module Compression Brotli Gzip</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>

<!-- remove this line after Fleck has been removed -->
<NoWarn>CS1591,CS1587,CS1572,CS1573,CS0612,CS0618</NoWarn>

</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions Modules/Compression/Providers/WrappedRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ public WrappedRequest(IRequest inner, Stream decompressedContent)

public IResponseBuilder Respond() => _inner.Respond();

public UpgradeInfo Upgrade() => _inner.Upgrade();

public void Dispose()
{
_decompressedContent.Dispose();
Expand Down
8 changes: 0 additions & 8 deletions Modules/IO/Tracking/ChangeTrackingResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ public async ValueTask WriteAsync(Stream target, uint bufferSize)
/// <returns>True if the content has changed, false otherwise</returns>
public async ValueTask<bool> CheckChangedAsync() => await CalculateChecksumAsync() != _lastChecksum;

/// <summary>
/// True, if the content of the resource has changed
/// since <see cref="GetContentAsync()" /> has been called
/// the last time.
/// </summary>
[Obsolete("Use CheckChangedAsync() instead. This method will be removed in GenHTTP 11.")]
public ValueTask<bool> HasChanged() => CheckChangedAsync();

#endregion

}
1 change: 0 additions & 1 deletion Modules/Inspection/Concern/InspectionConcern.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public InspectionConcern(IHandler content, SerializationRegistry serialization)
},
Response = (content != null) ? new {
Status = content.Status.RawStatus,
Upgraded = content.Upgraded,
Expires = content.Expires,
Modified = content.Modified,
Headers = content.Headers,
Expand Down
3 changes: 0 additions & 3 deletions Modules/Inspection/GenHTTP.Modules.Inspection.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
<PackageTags>GenHTTP HTTP Webserver C# Module Debugging Debug Inspection Inspector</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>

<!-- remove this line after Fleck has been removed -->
<NoWarn>CS1591,CS1587,CS1572,CS1573,CS0612,CS0618</NoWarn>

</PropertyGroup>

<ItemGroup>
Expand Down
16 changes: 6 additions & 10 deletions Modules/Websockets/GenHTTP.Modules.Websockets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,22 @@
<PackageTags>GenHTTP HTTP Webserver C# Module Websockets</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>

<!-- remove this line after Fleck has been removed -->
<NoWarn>CS1591,CS1587,CS1572,CS1573,CS0612,CS0618</NoWarn>

</PropertyGroup>

<ItemGroup>

<PackageReference Include="System.IO.Pipelines" Version="10.0.2" />
<PackageReference Include="System.IO.Pipelines" Version="10.0.2"/>

<ProjectReference Include="..\..\API\GenHTTP.Api.csproj"/>

<!-- remove together with fleck -->
<ProjectReference Include="..\..\Engine\Shared\GenHTTP.Engine.Shared.csproj" />

<PackageReference Include="Fleck" Version="1.2.0" />

<ProjectReference Include="..\Conversion\GenHTTP.Modules.Conversion.csproj" />

</ItemGroup>

<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="" />

<None Include="README.md" Pack="true" PackagePath=""/>

</ItemGroup>

</Project>
Loading
Loading