aboutsummaryrefslogtreecommitdiff
path: root/lib/Net.Http
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2023-06-16 13:33:43 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2023-06-16 13:33:43 -0400
commit44f25885437d6d09ea04cf74db4556df95821d56 (patch)
treeb7876edf7b36f0c56ec9bcd947dcbcbb4a9b6a1f /lib/Net.Http
parentabbfe728fde9e0a5643b3c4e85d1cd27b15c59f4 (diff)
Some tcp buf, minor bits and bobs
Diffstat (limited to 'lib/Net.Http')
-rw-r--r--lib/Net.Http/src/Core/HttpServerProcessing.cs9
-rw-r--r--lib/Net.Http/src/Core/Request/HttpInputStream.cs28
-rw-r--r--lib/Net.Http/src/Core/Response/HttpContextResponseWriting.cs15
-rw-r--r--lib/Net.Http/src/Helpers/MimeLookups.cs1
4 files changed, 36 insertions, 17 deletions
diff --git a/lib/Net.Http/src/Core/HttpServerProcessing.cs b/lib/Net.Http/src/Core/HttpServerProcessing.cs
index 5056d35..ad3ba80 100644
--- a/lib/Net.Http/src/Core/HttpServerProcessing.cs
+++ b/lib/Net.Http/src/Core/HttpServerProcessing.cs
@@ -74,7 +74,7 @@ namespace VNLib.Net.Http
break;
}
- //Set inactive keeaplive timeout
+ //Reset inactive keeaplive timeout, when expired the following read will throw a cancealltion exception
transportContext.ConnectionStream.ReadTimeout = (int)Config.ConnectionKeepAlive.TotalMilliseconds;
//"Peek" or wait for more data to begin another request (may throw timeout exception when timmed out)
@@ -109,7 +109,12 @@ namespace VNLib.Net.Http
{
WriteSocketExecption(se);
}
- catch(OperationCanceledException oce)
+ //Catch wrapped OC exceptions
+ catch (IOException ioe) when (ioe.InnerException is OperationCanceledException oce)
+ {
+ Config.ServerLog.Debug("Failed to receive transport data within a timeout period {m}, connection closed", oce.Message);
+ }
+ catch (OperationCanceledException oce)
{
Config.ServerLog.Debug("Failed to receive transport data within a timeout period {m}, connection closed", oce.Message);
}
diff --git a/lib/Net.Http/src/Core/Request/HttpInputStream.cs b/lib/Net.Http/src/Core/Request/HttpInputStream.cs
index be479c6..3d34445 100644
--- a/lib/Net.Http/src/Core/Request/HttpInputStream.cs
+++ b/lib/Net.Http/src/Core/Request/HttpInputStream.cs
@@ -200,13 +200,13 @@ namespace VNLib.Net.Http.Core
/// </summary>
/// <param name="bufMan">The buffer manager to request the discard buffer from</param>
/// <returns>A task that represents the discard operations</returns>
- public async ValueTask DiscardRemainingAsync(IHttpBufferManager bufMan)
+ public ValueTask DiscardRemainingAsync(IHttpBufferManager bufMan)
{
long remaining = Remaining;
if(remaining == 0)
{
- return;
+ return ValueTask.CompletedTask;
}
//See if all data has already been buffered
@@ -214,21 +214,27 @@ namespace VNLib.Net.Http.Core
{
//All data has been buffred, so just clear the buffer
_position = Length;
+ return ValueTask.CompletedTask;
}
//We must actaully disacrd data from the stream
else
{
- //Reqest discard buffer
- Memory<byte> discardBuffer = bufMan.GetDiscardBuffer();
+ return DiscardStreamDataAsync(bufMan);
+ }
+ }
+
+ private async ValueTask DiscardStreamDataAsync(IHttpBufferManager bufMan)
+ {
+ //Reqest discard buffer
+ Memory<byte> discardBuffer = bufMan.GetDiscardBuffer();
- int read;
- do
- {
- //Read data to the discard buffer until reading is completed (read == 0)
- read = await ReadAsync(discardBuffer, CancellationToken.None).ConfigureAwait(true);
+ int read;
+ do
+ {
+ //Read data to the discard buffer until reading is completed (read == 0)
+ read = await ReadAsync(discardBuffer, CancellationToken.None).ConfigureAwait(true);
- } while (read != 0);
- }
+ } while (read != 0);
}
public override long Seek(long offset, SeekOrigin origin)
diff --git a/lib/Net.Http/src/Core/Response/HttpContextResponseWriting.cs b/lib/Net.Http/src/Core/Response/HttpContextResponseWriting.cs
index 6bc92ff..2aab2d3 100644
--- a/lib/Net.Http/src/Core/Response/HttpContextResponseWriting.cs
+++ b/lib/Net.Http/src/Core/Response/HttpContextResponseWriting.cs
@@ -29,7 +29,6 @@ using System.Net;
using System.Threading;
using System.Threading.Tasks;
-
namespace VNLib.Net.Http.Core
{
@@ -50,16 +49,24 @@ namespace VNLib.Net.Http.Core
{
//Parallel the write and discard
Task response = WriteResponseInternalAsync(cancellation);
- Task discard = discardTask.AsTask();
- await Task.WhenAll(response, discard);
+ if (discardTask.IsCompletedSuccessfully)
+ {
+ //If discard is already complete, await the response
+ await response;
+ }
+ else
+ {
+ //If discard is not complete, await both
+ await Task.WhenAll(discardTask.AsTask(), response);
+ }
}
else
{
await discardTask;
}
- //Close response
+ //Close response once send and discard are complete
await Response.CloseAsync();
}
diff --git a/lib/Net.Http/src/Helpers/MimeLookups.cs b/lib/Net.Http/src/Helpers/MimeLookups.cs
index 03bc59d..17582bb 100644
--- a/lib/Net.Http/src/Helpers/MimeLookups.cs
+++ b/lib/Net.Http/src/Helpers/MimeLookups.cs
@@ -3207,6 +3207,7 @@ namespace VNLib.Net.Http
{ "application/vnd.openxmlformats-officedocument.spreadsheetml.template", ContentType.Xltx },
{ "audio/xm", ContentType.Xm },
{ "application/xml", ContentType.Xml },
+ { "text/xml", ContentType.Xml },
{ "application/xcap-ns+xml", ContentType.Xns },
{ "application/vnd.olpc-sugar", ContentType.Xo },
{ "application/xop+xml", ContentType.Xop },