aboutsummaryrefslogtreecommitdiff
path: root/lib/Net.Http
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Net.Http')
-rw-r--r--lib/Net.Http/src/AlternateProtocolBase.cs2
-rw-r--r--lib/Net.Http/src/Core/AlternateProtocolTransportStreamWrapper.cs (renamed from lib/Net.Http/src/Helpers/AlternateProtocolTransportStreamWrapper.cs)14
-rw-r--r--lib/Net.Http/src/Core/HttpEvent.cs2
-rw-r--r--lib/Net.Http/src/Core/HttpServerProcessing.cs14
-rw-r--r--lib/Net.Http/src/Core/Request/HttpRequest.cs55
-rw-r--r--lib/Net.Http/src/IHttpEvent.cs2
-rw-r--r--lib/Net.Http/src/VNLib.Net.Http.csproj12
7 files changed, 43 insertions, 58 deletions
diff --git a/lib/Net.Http/src/AlternateProtocolBase.cs b/lib/Net.Http/src/AlternateProtocolBase.cs
index 929bc33..e7b9a61 100644
--- a/lib/Net.Http/src/AlternateProtocolBase.cs
+++ b/lib/Net.Http/src/AlternateProtocolBase.cs
@@ -58,7 +58,7 @@ namespace VNLib.Net.Http
try
{
//Call child initialize method
- await RunAsync(new AlternateProtocolTransportStreamWrapper(transport));
+ await RunAsync(transport);
CancelSource.Cancel();
}
finally
diff --git a/lib/Net.Http/src/Helpers/AlternateProtocolTransportStreamWrapper.cs b/lib/Net.Http/src/Core/AlternateProtocolTransportStreamWrapper.cs
index d81b7eb..8661e15 100644
--- a/lib/Net.Http/src/Helpers/AlternateProtocolTransportStreamWrapper.cs
+++ b/lib/Net.Http/src/Core/AlternateProtocolTransportStreamWrapper.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2022 Vaughn Nugent
+* Copyright (c) 2024 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Net.Http
@@ -34,19 +34,15 @@ namespace VNLib.Net.Http.Core
{
internal sealed class AlternateProtocolTransportStreamWrapper : BackingStream<Stream>
{
- public AlternateProtocolTransportStreamWrapper(Stream transport)
- {
- this.BaseStream = transport;
- }
+ public AlternateProtocolTransportStreamWrapper(Stream transport) => BaseStream = transport;
//Do not allow the caller to dispose the transport stream
protected override void Dispose(bool disposing)
{ }
- public override ValueTask DisposeAsync()
- {
- return ValueTask.CompletedTask;
- }
+
+ public override ValueTask DisposeAsync() => ValueTask.CompletedTask;
+
public override void Close()
{}
}
diff --git a/lib/Net.Http/src/Core/HttpEvent.cs b/lib/Net.Http/src/Core/HttpEvent.cs
index e6f3b5b..8867a12 100644
--- a/lib/Net.Http/src/Core/HttpEvent.cs
+++ b/lib/Net.Http/src/Core/HttpEvent.cs
@@ -50,7 +50,7 @@ namespace VNLib.Net.Http
IConnectionInfo IHttpEvent.Server => _ci;
///<inheritdoc/>
- HttpServer IHttpEvent.OriginServer => Context.ParentServer;
+ IHttpServer IHttpEvent.OriginServer => Context.ParentServer;
///<inheritdoc/>
IReadOnlyDictionary<string, string> IHttpEvent.QueryArgs => Context.Request.QueryArgs;
diff --git a/lib/Net.Http/src/Core/HttpServerProcessing.cs b/lib/Net.Http/src/Core/HttpServerProcessing.cs
index 4595f3e..8a9ca07 100644
--- a/lib/Net.Http/src/Core/HttpServerProcessing.cs
+++ b/lib/Net.Http/src/Core/HttpServerProcessing.cs
@@ -101,8 +101,18 @@ namespace VNLib.Net.Http
stream.ReadTimeout = Timeout.Infinite;
stream.WriteTimeout = Timeout.Infinite;
+ /*
+ * Create a transport wrapper so callers cannot take control of the transport
+ * hooks such as disposing. Timeouts are allowed to be changed, not exactly
+ * our problem.
+ */
+
+#pragma warning disable CA2000 // Dispose objects before losing scope
+ AlternateProtocolTransportStreamWrapper apWrapper = new(transport:stream);
+#pragma warning restore CA2000 // Dispose objects before losing scope
+
//Listen on the alternate protocol
- await ap.RunAsync(stream, StopToken!.Token).ConfigureAwait(false);
+ await ap.RunAsync(apWrapper, StopToken!.Token).ConfigureAwait(false);
}
}
//Catch wrapped socket exceptions
@@ -131,7 +141,7 @@ namespace VNLib.Net.Http
//Dec open connection count
Interlocked.Decrement(ref OpenConnectionCount);
- //Return the context for normal operation
+ //Return the context for normal operation (alternate protocol will return before now so it will be null)
if(context != null)
{
//Return context to store
diff --git a/lib/Net.Http/src/Core/Request/HttpRequest.cs b/lib/Net.Http/src/Core/Request/HttpRequest.cs
index 43b3e5f..ce8257f 100644
--- a/lib/Net.Http/src/Core/Request/HttpRequest.cs
+++ b/lib/Net.Http/src/Core/Request/HttpRequest.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2023 Vaughn Nugent
+* Copyright (c) 2024 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Net.Http
@@ -32,24 +32,23 @@ using VNLib.Utils.Extensions;
namespace VNLib.Net.Http.Core
{
-
- internal sealed class HttpRequest : IHttpLifeCycle
+ internal sealed class HttpRequest(IHttpContextInformation contextInfo, ushort maxUploads) : IHttpLifeCycle
#if DEBUG
,IStringSerializeable
#endif
{
- public readonly VnWebHeaderCollection Headers;
- public readonly List<string> Accept;
- public readonly List<string> AcceptLanguage;
- public readonly Dictionary<string, string> Cookies;
- public readonly Dictionary<string, string> RequestArgs;
- public readonly Dictionary<string, string> QueryArgs;
+ public readonly VnWebHeaderCollection Headers = new();
+ public readonly List<string> Accept = new(8);
+ public readonly List<string> AcceptLanguage = new(8);
+ public readonly Dictionary<string, string> Cookies = new(5, StringComparer.OrdinalIgnoreCase);
+ public readonly Dictionary<string, string> RequestArgs = new(StringComparer.OrdinalIgnoreCase);
+ public readonly Dictionary<string, string> QueryArgs = new(StringComparer.OrdinalIgnoreCase);
/// <summary>
/// A transport stream wrapper that is positioned for reading
/// the entity body from the input stream
/// </summary>
- public readonly HttpInputStream InputStream;
+ public readonly HttpInputStream InputStream = new(contextInfo);
/*
* Evil mutable structure that stores the http request state.
@@ -63,7 +62,7 @@ namespace VNLib.Net.Http.Core
* null/default values and easy reset.
*/
private HttpRequestState _state;
- private readonly FileUpload[] _uploads;
+ private readonly FileUpload[] _uploads = new FileUpload[maxUploads];
/// <summary>
/// Gets a mutable structure ref only used to initalize the request
@@ -77,20 +76,6 @@ namespace VNLib.Net.Http.Core
/// </summary>
internal ref readonly HttpRequestState State => ref _state;
- public HttpRequest(IHttpContextInformation contextInfo, ushort maxUploads)
- {
- //Create new collection for headers
- _uploads = new FileUpload[maxUploads];
- Headers = new();
- Cookies = new(5, StringComparer.OrdinalIgnoreCase);
- RequestArgs = new(StringComparer.OrdinalIgnoreCase);
- QueryArgs = new(StringComparer.OrdinalIgnoreCase);
- Accept = new(8);
- AcceptLanguage = new(8);
- //New reusable input stream
- InputStream = new(contextInfo);
- }
-
void IHttpLifeCycle.OnPrepare()
{ }
@@ -147,10 +132,22 @@ namespace VNLib.Net.Http.Core
}
}
+ /// <summary>
+ /// Checks if another upload can be added to the request
+ /// </summary>
+ /// <returns>A value indicating if another file upload can be added to the array</returns>
+ public bool CanAddUpload() => _state.UploadCount < _uploads.Length;
+
+ /// <summary>
+ /// Attempts to add a file upload to the request if there
+ /// is room for it. If there is no room, it will be ignored.
+ /// See <see cref="CanAddUpload"/> to check if another upload can be added.
+ /// </summary>
+ /// <param name="upload">The file upload structure to add to the list</param>
public void AddFileUpload(in FileUpload upload)
{
//See if there is room for another upload
- if (_state.UploadCount < _uploads.Length)
+ if (CanAddUpload())
{
//Add file to upload array and increment upload count
_uploads[_state.UploadCount++] = upload;
@@ -158,12 +155,6 @@ namespace VNLib.Net.Http.Core
}
/// <summary>
- /// Checks if another upload can be added to the request
- /// </summary>
- /// <returns>A value indicating if another file upload can be added to the array</returns>
- public bool CanAddUpload() => _state.UploadCount < _uploads.Length;
-
- /// <summary>
/// Creates a new array and copies the uploads to it.
/// </summary>
/// <returns>The array clone of the file uploads</returns>
diff --git a/lib/Net.Http/src/IHttpEvent.cs b/lib/Net.Http/src/IHttpEvent.cs
index 917f959..ce7f6ff 100644
--- a/lib/Net.Http/src/IHttpEvent.cs
+++ b/lib/Net.Http/src/IHttpEvent.cs
@@ -42,7 +42,7 @@ namespace VNLib.Net.Http
/// <summary>
/// The <see cref="HttpServer"/> that this connection originated from
/// </summary>
- HttpServer OriginServer { get; }
+ IHttpServer OriginServer { get; }
/// <summary>
/// If the request has query arguments they are stored in key value format
diff --git a/lib/Net.Http/src/VNLib.Net.Http.csproj b/lib/Net.Http/src/VNLib.Net.Http.csproj
index 43224fe..b491cc1 100644
--- a/lib/Net.Http/src/VNLib.Net.Http.csproj
+++ b/lib/Net.Http/src/VNLib.Net.Http.csproj
@@ -25,18 +25,6 @@
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
</PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)'=='Debug'">
- <CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
- </PropertyGroup>
-
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
- <Deterministic>False</Deterministic>
- </PropertyGroup>
-
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
- <Deterministic>False</Deterministic>
- </PropertyGroup>
-
<ItemGroup>
<PackageReference Include="ErrorProne.NET.CoreAnalyzers" Version="0.1.2">
<PrivateAssets>all</PrivateAssets>