diff options
Diffstat (limited to 'lib/Net.Http/src')
-rw-r--r-- | lib/Net.Http/src/Core/HttpServerProcessing.cs | 9 | ||||
-rw-r--r-- | lib/Net.Http/src/Core/Request/HttpInputStream.cs | 28 | ||||
-rw-r--r-- | lib/Net.Http/src/Core/Response/HttpContextResponseWriting.cs | 15 | ||||
-rw-r--r-- | lib/Net.Http/src/Helpers/MimeLookups.cs | 1 |
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 }, |