From 64284c69b9bcd5e3dab3b513dcc706f85f4b253e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20N=C3=A4geli?= Date: Tue, 23 Apr 2024 15:58:26 +0200 Subject: [PATCH] Various performance improvements (#482) - Call AdvanceTo in RequestBuffer only once - Remove ConfigureAwait() calls - Do not flush in pipelining mode --- Engine/Infrastructure/CoreRouter.cs | 2 +- Engine/Infrastructure/Endpoints/EndPoint.cs | 9 ++--- .../Endpoints/SecureEndPoint.cs | 6 ++-- Engine/Protocol/ChunkedStream.cs | 6 ++-- Engine/Protocol/ClientHandler.cs | 14 ++++---- Engine/Protocol/Parser/RequestScanner.cs | 2 +- Engine/Protocol/RequestBuffer.cs | 22 +++++++------ Engine/Protocol/RequestContentParser.cs | 2 +- Engine/Protocol/ResponseHandler.cs | 33 +++++++++---------- Engine/Utilities/PoolBufferedStream.cs | 10 +++--- .../Concern/WebAuthenticationConcern.cs | 4 +-- .../Authentication/ApiKey/ApiKeyConcern.cs | 2 +- .../Basic/BasicAuthenticationConcern.cs | 4 +-- .../Validation/CacheValidationHandler.cs | 4 +-- .../Providers/CompressionConcern.cs | 2 +- .../Provider/ListingProvider.cs | 4 +-- .../Provider/ListingRouter.cs | 2 +- Modules/ErrorHandling/Provider/ErrorSentry.cs | 2 +- Modules/IO/FileSystem/FileResource.cs | 2 +- Modules/IO/ResponseBuilderExtensions.cs | 2 +- Modules/IO/Streaming/ResourceContent.cs | 2 +- Modules/Layouting/Provider/LayoutRouter.cs | 2 +- Modules/Markdown/MarkdownPageProvider.cs | 2 +- Modules/Pages/Combined/CombinedPageContent.cs | 2 +- .../Pages/Combined/CombinedPageProvider.cs | 4 +-- Modules/Pages/Rendering/PageProvider.cs | 2 +- Modules/Pages/Rendering/RenderedContent.cs | 4 +-- .../Placeholders/Providers/PageProvider.cs | 4 +-- .../Providers/PlaceholderPageProvider.cs | 4 +-- Modules/Reflection/ResponseProvider.cs | 8 ++--- .../Provider/ClientResponseContent.cs | 2 +- .../Provider/ReverseProxyProvider.cs | 2 +- Modules/Security/Cors/CorsPolicyHandler.cs | 2 +- .../Providers/SecureUpgradeConcern.cs | 6 ++-- .../Providers/SnifferPreventionConcern.cs | 2 +- .../Providers/StrictTransportConcern.cs | 2 +- .../Provider/SinglePageProvider.cs | 4 +-- .../Provider/StaticWebsiteHandler.cs | 2 +- Modules/Websites/Sites/WebsiteRenderer.cs | 6 ++-- Modules/Websites/Sites/WebsiteRouter.cs | 10 +++--- Playground/Program.cs | 6 ++-- 41 files changed, 106 insertions(+), 106 deletions(-) diff --git a/Engine/Infrastructure/CoreRouter.cs b/Engine/Infrastructure/CoreRouter.cs index f4e45d9c..9aa8ecb7 100644 --- a/Engine/Infrastructure/CoreRouter.cs +++ b/Engine/Infrastructure/CoreRouter.cs @@ -68,7 +68,7 @@ internal CoreRouter(IHandlerBuilder content, IEnumerable concer public async ValueTask PrepareAsync() { - await Content.PrepareAsync().ConfigureAwait(false); + await Content.PrepareAsync(); await Template.PrepareAsync(); diff --git a/Engine/Infrastructure/Endpoints/EndPoint.cs b/Engine/Infrastructure/Endpoints/EndPoint.cs index 8a3baaba..d7d3a139 100644 --- a/Engine/Infrastructure/Endpoints/EndPoint.cs +++ b/Engine/Infrastructure/Endpoints/EndPoint.cs @@ -65,7 +65,7 @@ protected EndPoint(IServer server, IPEndPoint endPoint, NetworkConfiguration con throw new BindingException($"Failed to bind to {endPoint}.", e); } - Task = Task.Run(() => Listen().ConfigureAwait(false)); + Task = Task.Run(() => Listen()); } #endregion @@ -78,7 +78,7 @@ private async Task Listen() { do { - Handle(await Socket.AcceptAsync().ConfigureAwait(false)); + Handle(await Socket.AcceptAsync()); } while (!shuttingDown); } @@ -95,14 +95,15 @@ private void Handle(Socket client) { using var _ = ExecutionContext.SuppressFlow(); - Task.Run(() => Accept(client).ConfigureAwait(false)) - .ConfigureAwait(false); + Task.Run(() => Accept(client)); } protected abstract PooledValueTask Accept(Socket client); protected PooledValueTask Handle(Socket client, Stream inputStream) { + client.NoDelay = true; + return new ClientHandler(client, inputStream, Server, this, Configuration).Run(); } diff --git a/Engine/Infrastructure/Endpoints/SecureEndPoint.cs b/Engine/Infrastructure/Endpoints/SecureEndPoint.cs index 0dc7aece..35b1625a 100644 --- a/Engine/Infrastructure/Endpoints/SecureEndPoint.cs +++ b/Engine/Infrastructure/Endpoints/SecureEndPoint.cs @@ -54,11 +54,11 @@ internal SecureEndPoint(IServer server, IPEndPoint endPoint, SecurityConfigurati protected override async PooledValueTask Accept(Socket client) { - var stream = await TryAuthenticate(client).ConfigureAwait(false); + var stream = await TryAuthenticate(client); if (stream is not null) { - await Handle(client, new PoolBufferedStream(stream)).ConfigureAwait(false); + await Handle(client, new PoolBufferedStream(stream)); } else { @@ -80,7 +80,7 @@ protected override async PooledValueTask Accept(Socket client) { var stream = new SslStream(new NetworkStream(client), false); - await stream.AuthenticateAsServerAsync(AuthenticationOptions, CancellationToken.None).ConfigureAwait(false); + await stream.AuthenticateAsServerAsync(AuthenticationOptions, CancellationToken.None); return stream; } diff --git a/Engine/Protocol/ChunkedStream.cs b/Engine/Protocol/ChunkedStream.cs index 11ced0cc..79f4011a 100644 --- a/Engine/Protocol/ChunkedStream.cs +++ b/Engine/Protocol/ChunkedStream.cs @@ -86,7 +86,7 @@ public override async Task WriteAsync(byte[] buffer, int offset, int count, Canc { if (count > 0) { - await WriteAsync(count).ConfigureAwait(false); + await WriteAsync(count); await WriteAsync(NL); await Target.WriteAsync(buffer.AsMemory(offset, count), cancellationToken); @@ -99,7 +99,7 @@ public override async ValueTask WriteAsync(ReadOnlyMemory buffer, Cancella { if (!buffer.IsEmpty) { - await WriteAsync(buffer.Length).ConfigureAwait(false); + await WriteAsync(buffer.Length); await WriteAsync(NL); await Target.WriteAsync(buffer, cancellationToken); @@ -110,7 +110,7 @@ public override async ValueTask WriteAsync(ReadOnlyMemory buffer, Cancella public async ValueTask FinishAsync() { - await WriteAsync("0").ConfigureAwait(false); + await WriteAsync("0"); await WriteAsync(NL); await WriteAsync(NL); diff --git a/Engine/Protocol/ClientHandler.cs b/Engine/Protocol/ClientHandler.cs index f435c92d..4989d0d7 100644 --- a/Engine/Protocol/ClientHandler.cs +++ b/Engine/Protocol/ClientHandler.cs @@ -59,7 +59,7 @@ internal ClientHandler(Socket socket, Stream stream, IServer server, IEndPoint e Stream = stream; - ResponseHandler = new ResponseHandler(Server, Stream, Connection, Configuration); + ResponseHandler = new ResponseHandler(Server, Stream, Configuration); } #endregion @@ -70,7 +70,7 @@ internal async PooledValueTask Run() { try { - await HandlePipe(PipeReader.Create(Stream, READER_OPTIONS)).ConfigureAwait(false); + await HandlePipe(PipeReader.Create(Stream, READER_OPTIONS)); } catch (Exception e) { @@ -115,9 +115,9 @@ private async PooledValueTask HandlePipe(PipeReader reader) RequestBuilder? request; - while (Server.Running && (request = await parser.TryParseAsync(buffer).ConfigureAwait(false)) is not null) + while (Server.Running && (request = await parser.TryParseAsync(buffer)) is not null) { - if (!await HandleRequest(request)) + if (!await HandleRequest(request, !buffer.ReadRequired)) { break; } @@ -129,7 +129,7 @@ private async PooledValueTask HandlePipe(PipeReader reader) } } - private async PooledValueTask HandleRequest(RequestBuilder builder) + private async PooledValueTask HandleRequest(RequestBuilder builder, bool dataRemaining) { var address = (Connection.RemoteEndPoint as IPEndPoint)?.Address; @@ -139,9 +139,9 @@ private async PooledValueTask HandleRequest(RequestBuilder builder) bool keepAlive = (bool)KeepAlive; - using var response = await Server.Handler.HandleAsync(request).ConfigureAwait(false) ?? throw new InvalidOperationException("The root request handler did not return a response"); + using var response = await Server.Handler.HandleAsync(request) ?? throw new InvalidOperationException("The root request handler did not return a response"); - var success = await ResponseHandler.Handle(request, response, keepAlive); + var success = await ResponseHandler.Handle(request, response, keepAlive, dataRemaining); if (!success || !keepAlive) { diff --git a/Engine/Protocol/Parser/RequestScanner.cs b/Engine/Protocol/Parser/RequestScanner.cs index fe5833ab..b2fc722c 100644 --- a/Engine/Protocol/Parser/RequestScanner.cs +++ b/Engine/Protocol/Parser/RequestScanner.cs @@ -147,7 +147,7 @@ private static async PooledValueTask Fill(RequestBuffer buffer, bool force { if (buffer.ReadRequired || force) { - await buffer.Read(force).ConfigureAwait(false); + await buffer.Read(force); } return !buffer.Data.IsEmpty; diff --git a/Engine/Protocol/RequestBuffer.cs b/Engine/Protocol/RequestBuffer.cs index b4388ba2..1fe383b2 100644 --- a/Engine/Protocol/RequestBuffer.cs +++ b/Engine/Protocol/RequestBuffer.cs @@ -25,6 +25,7 @@ namespace GenHTTP.Engine.Protocol /// internal sealed class RequestBuffer : IDisposable { + private ReadOnlySequence? _Data; #region Get-/Setters @@ -34,9 +35,9 @@ internal sealed class RequestBuffer : IDisposable private CancellationTokenSource? Cancellation { get; set; } - internal ReadOnlySequence Data { get; private set; } + internal ReadOnlySequence Data => _Data ?? new(); - internal bool ReadRequired => Data.IsEmpty; + internal bool ReadRequired => (_Data == null) || _Data.Value.IsEmpty; #endregion @@ -46,8 +47,6 @@ internal RequestBuffer(PipeReader reader, NetworkConfiguration configuration) { Reader = reader; Configuration = configuration; - - Data = new(); } #endregion @@ -56,8 +55,13 @@ internal RequestBuffer(PipeReader reader, NetworkConfiguration configuration) internal async PooledValueTask Read(bool force = false) { - if ((Data.Length == 0) || force) + if (ReadRequired || force) { + if (_Data != null) + { + Reader.AdvanceTo(_Data.Value.Start); + } + if (Cancellation is null) { Cancellation = new(); @@ -67,7 +71,7 @@ internal RequestBuffer(PipeReader reader, NetworkConfiguration configuration) { Cancellation.CancelAfter(Configuration.RequestReadTimeout); - Data = (await Reader.ReadAsync(Cancellation.Token).ConfigureAwait(false)).Buffer; + _Data = (await Reader.ReadAsync(Cancellation.Token)).Buffer; Cancellation.CancelAfter(int.MaxValue); } @@ -85,14 +89,12 @@ internal RequestBuffer(PipeReader reader, NetworkConfiguration configuration) internal void Advance(SequencePosition position) { - Data = Data.Slice(position); - Reader.AdvanceTo(Data.Start); + _Data = Data.Slice(position); } internal void Advance(long bytes) { - Data = Data.Slice(bytes); - Reader.AdvanceTo(Data.Start); + _Data = Data.Slice(bytes); } #endregion diff --git a/Engine/Protocol/RequestContentParser.cs b/Engine/Protocol/RequestContentParser.cs index 45aa6800..13a5f475 100644 --- a/Engine/Protocol/RequestContentParser.cs +++ b/Engine/Protocol/RequestContentParser.cs @@ -42,7 +42,7 @@ internal async Task GetBody(RequestBuffer buffer) while (toFetch > 0) { - await buffer.Read().ConfigureAwait(false); + await buffer.Read(); var toRead = Math.Min(buffer.Data.Length, Math.Min(Configuration.TransferBufferSize, toFetch)); diff --git a/Engine/Protocol/ResponseHandler.cs b/Engine/Protocol/ResponseHandler.cs index 2fb3eb97..c3feef85 100644 --- a/Engine/Protocol/ResponseHandler.cs +++ b/Engine/Protocol/ResponseHandler.cs @@ -1,7 +1,6 @@ using System; using System.Buffers; using System.IO; -using System.Net.Sockets; using System.Text; using System.Threading.Tasks; @@ -30,20 +29,17 @@ internal sealed class ResponseHandler private Stream OutputStream { get; } - private Socket Socket { get; } - internal NetworkConfiguration Configuration { get; } #endregion #region Initialization - internal ResponseHandler(IServer server, Stream outputstream, Socket socket, NetworkConfiguration configuration) + internal ResponseHandler(IServer server, Stream outputstream, NetworkConfiguration configuration) { Server = server; OutputStream = outputstream; - Socket = socket; Configuration = configuration; } @@ -52,11 +48,11 @@ internal ResponseHandler(IServer server, Stream outputstream, Socket socket, Net #region Functionality - internal async ValueTask Handle(IRequest request, IResponse response, bool keepAlive) + internal async ValueTask Handle(IRequest request, IResponse response, bool keepAlive, bool dataRemaining) { try { - await WriteStatus(request, response).ConfigureAwait(false); + await WriteStatus(request, response); await WriteHeader(response, keepAlive); @@ -67,11 +63,12 @@ internal async ValueTask Handle(IRequest request, IResponse response, bool await WriteBody(response); } - Socket.NoDelay = true; - - await OutputStream.FlushAsync(); - - Socket.NoDelay = false; + // flush if the client waits for this response + // otherwise save flushes for improved performance when pipelining + if (!dataRemaining) + { + await OutputStream.FlushAsync(); + } Server.Companion?.OnRequestHandled(request, response); @@ -104,11 +101,11 @@ private async ValueTask WriteHeader(IResponse response, bool keepAlive) { if (response.Headers.TryGetValue(SERVER_HEADER, out var server)) { - await WriteHeaderLine(SERVER_HEADER, server).ConfigureAwait(false); + await WriteHeaderLine(SERVER_HEADER, server); } else { - await Write("Server: GenHTTP/", Server.Version, NL).ConfigureAwait(false); + await Write("Server: GenHTTP/", Server.Version, NL); } await WriteHeaderLine("Date", DateHeader.GetValue()); @@ -183,13 +180,13 @@ private async ValueTask WriteBody(IResponse response) { using var chunked = new ChunkedStream(OutputStream); - await response.Content.WriteAsync(chunked, Configuration.TransferBufferSize).ConfigureAwait(false); + await response.Content.WriteAsync(chunked, Configuration.TransferBufferSize); await chunked.FinishAsync(); } else { - await response.Content.WriteAsync(OutputStream, Configuration.TransferBufferSize).ConfigureAwait(false); + await response.Content.WriteAsync(OutputStream, Configuration.TransferBufferSize); } } } @@ -204,7 +201,7 @@ private async ValueTask WriteBody(IResponse response) private async ValueTask WriteCookie(Cookie cookie) { - await Write("Set-Cookie: ", cookie.Name, "=", cookie.Value).ConfigureAwait(false); + await Write("Set-Cookie: ", cookie.Name, "=", cookie.Value); if (cookie.MaxAge is not null) { @@ -264,7 +261,7 @@ private async ValueTask Write(string part1, string? part2 = null, string? part3 ASCII.GetBytes(part7, 0, part7.Length, buffer, index); } - await OutputStream.WriteAsync(buffer.AsMemory(0, length)).ConfigureAwait(false); + await OutputStream.WriteAsync(buffer.AsMemory(0, length)); } finally { diff --git a/Engine/Utilities/PoolBufferedStream.cs b/Engine/Utilities/PoolBufferedStream.cs index 79c2246e..64260358 100644 --- a/Engine/Utilities/PoolBufferedStream.cs +++ b/Engine/Utilities/PoolBufferedStream.cs @@ -55,7 +55,7 @@ public PoolBufferedStream(Stream stream) { Stream = stream; - Buffer = POOL.Rent(8192); + Buffer = POOL.Rent(4096); Current = 0; } @@ -115,12 +115,12 @@ public override async ValueTask WriteAsync(ReadOnlyMemory buffer, Cancella if (Current == Buffer.Length) { - await WriteBufferAsync(cancellationToken).ConfigureAwait(false); + await WriteBufferAsync(cancellationToken); } } else { - await WriteBufferAsync(cancellationToken).ConfigureAwait(false); + await WriteBufferAsync(cancellationToken); await Stream.WriteAsync(buffer, cancellationToken); } @@ -135,7 +135,7 @@ public override void Flush() public override async Task FlushAsync(CancellationToken cancellationToken) { - await WriteBufferAsync(cancellationToken).ConfigureAwait(false); + await WriteBufferAsync(cancellationToken); await Stream.FlushAsync(cancellationToken); } @@ -154,7 +154,7 @@ private async ValueTask WriteBufferAsync(CancellationToken cancellationToken) { if (Current > 0) { - await Stream.WriteAsync(Buffer.AsMemory(0, Current), cancellationToken).ConfigureAwait(false); + await Stream.WriteAsync(Buffer.AsMemory(0, Current), cancellationToken); Current = 0; } diff --git a/Modules/Authentication.Web/Concern/WebAuthenticationConcern.cs b/Modules/Authentication.Web/Concern/WebAuthenticationConcern.cs index 62c85edc..929696b4 100644 --- a/Modules/Authentication.Web/Concern/WebAuthenticationConcern.cs +++ b/Modules/Authentication.Web/Concern/WebAuthenticationConcern.cs @@ -67,10 +67,10 @@ public WebAuthenticationConcern(IHandler parent, Func conten { request.Target.Advance(); - return await ResourceHandler.HandleAsync(request).ConfigureAwait(false); + return await ResourceHandler.HandleAsync(request); } - if (await Integration.CheckSetupRequired(request).ConfigureAwait(false)) + if (await Integration.CheckSetupRequired(request)) { if (segment?.Value != Integration.SetupRoute) { diff --git a/Modules/Authentication/ApiKey/ApiKeyConcern.cs b/Modules/Authentication/ApiKey/ApiKeyConcern.cs index 02d51564..3ddb6b78 100644 --- a/Modules/Authentication/ApiKey/ApiKeyConcern.cs +++ b/Modules/Authentication/ApiKey/ApiKeyConcern.cs @@ -45,7 +45,7 @@ public ApiKeyConcern(IHandler parent, Func contentFactory, F if (key != null) { - var user = await Authenticator(request, key).ConfigureAwait(false); + var user = await Authenticator(request, key); if (user != null) { diff --git a/Modules/Authentication/Basic/BasicAuthenticationConcern.cs b/Modules/Authentication/Basic/BasicAuthenticationConcern.cs index a1830d9c..5ff85abf 100644 --- a/Modules/Authentication/Basic/BasicAuthenticationConcern.cs +++ b/Modules/Authentication/Basic/BasicAuthenticationConcern.cs @@ -61,7 +61,7 @@ public BasicAuthenticationConcern(IHandler parent, Func cont return GetChallenge(request); } - var user = await Authenticator(credentials.username, credentials.password).ConfigureAwait(false); + var user = await Authenticator(credentials.username, credentials.password); if (user is null) { @@ -70,7 +70,7 @@ public BasicAuthenticationConcern(IHandler parent, Func cont request.SetUser(user); - return await Content.HandleAsync(request).ConfigureAwait(false); + return await Content.HandleAsync(request); } private IResponse GetChallenge(IRequest request) diff --git a/Modules/ClientCaching/Validation/CacheValidationHandler.cs b/Modules/ClientCaching/Validation/CacheValidationHandler.cs index cda90ba0..c19d19f9 100644 --- a/Modules/ClientCaching/Validation/CacheValidationHandler.cs +++ b/Modules/ClientCaching/Validation/CacheValidationHandler.cs @@ -38,7 +38,7 @@ public CacheValidationHandler(IHandler parent, Func contentF public async ValueTask HandleAsync(IRequest request) { - var response = await Content.HandleAsync(request).ConfigureAwait(false); + var response = await Content.HandleAsync(request); if (request.HasType(_SupportedMethods)) { @@ -82,7 +82,7 @@ public CacheValidationHandler(IHandler parent, Func contentF if (response.Content is not null) { - var checksum = await response.Content.CalculateChecksumAsync().ConfigureAwait(false); + var checksum = await response.Content.CalculateChecksumAsync(); if (checksum is not null) { diff --git a/Modules/Compression/Providers/CompressionConcern.cs b/Modules/Compression/Providers/CompressionConcern.cs index f754b9de..01b6fa39 100644 --- a/Modules/Compression/Providers/CompressionConcern.cs +++ b/Modules/Compression/Providers/CompressionConcern.cs @@ -50,7 +50,7 @@ public CompressionConcern(IHandler parent, Func contentFacto public async ValueTask HandleAsync(IRequest request) { - var response = await Content.HandleAsync(request).ConfigureAwait(false); + var response = await Content.HandleAsync(request); if (response is not null) { diff --git a/Modules/DirectoryBrowsing/Provider/ListingProvider.cs b/Modules/DirectoryBrowsing/Provider/ListingProvider.cs index a8180817..bc4e87d5 100644 --- a/Modules/DirectoryBrowsing/Provider/ListingProvider.cs +++ b/Modules/DirectoryBrowsing/Provider/ListingProvider.cs @@ -41,9 +41,9 @@ public ListingProvider(IHandler parent, IResourceContainer container) var renderer = new ListingRenderer(); - var templateModel = new TemplateModel(request, this, GetPageInfo(request), null, await renderer.RenderAsync(model).ConfigureAwait(false)); + var templateModel = new TemplateModel(request, this, GetPageInfo(request), null, await renderer.RenderAsync(model)); - return (await this.GetPageAsync(request, templateModel).ConfigureAwait(false)).Build(); + return (await this.GetPageAsync(request, templateModel)).Build(); } public ValueTask PrepareAsync() => ValueTask.CompletedTask; diff --git a/Modules/DirectoryBrowsing/Provider/ListingRouter.cs b/Modules/DirectoryBrowsing/Provider/ListingRouter.cs index a77cc9e2..aa8f88a8 100644 --- a/Modules/DirectoryBrowsing/Provider/ListingRouter.cs +++ b/Modules/DirectoryBrowsing/Provider/ListingRouter.cs @@ -36,7 +36,7 @@ public ListingRouter(IHandler parent, IResourceTree tree) public async ValueTask HandleAsync(IRequest request) { - var (node, resource) = await Tree.Find(request.Target).ConfigureAwait(false); + var (node, resource) = await Tree.Find(request.Target); if (resource is not null) { diff --git a/Modules/ErrorHandling/Provider/ErrorSentry.cs b/Modules/ErrorHandling/Provider/ErrorSentry.cs index 7d57d176..29da6d11 100644 --- a/Modules/ErrorHandling/Provider/ErrorSentry.cs +++ b/Modules/ErrorHandling/Provider/ErrorSentry.cs @@ -44,7 +44,7 @@ public ErrorSentry(IHandler parent, Func contentFactory, IEr try { var response = await Content.HandleAsync(request) - .ConfigureAwait(false); + ; if (response is null) { diff --git a/Modules/IO/FileSystem/FileResource.cs b/Modules/IO/FileSystem/FileResource.cs index da915278..a8e03c4e 100644 --- a/Modules/IO/FileSystem/FileResource.cs +++ b/Modules/IO/FileSystem/FileResource.cs @@ -87,7 +87,7 @@ public async ValueTask WriteAsync(Stream target, uint bufferSize) { using var content = File.OpenRead(); - await content.CopyPooledAsync(target, bufferSize).ConfigureAwait(false); + await content.CopyPooledAsync(target, bufferSize); } #endregion diff --git a/Modules/IO/ResponseBuilderExtensions.cs b/Modules/IO/ResponseBuilderExtensions.cs index 014b193f..7badda15 100644 --- a/Modules/IO/ResponseBuilderExtensions.cs +++ b/Modules/IO/ResponseBuilderExtensions.cs @@ -74,7 +74,7 @@ public static class ResponseBuilderExtensions do { - read = await stream.ReadAsync(buffer).ConfigureAwait(false); + read = await stream.ReadAsync(buffer); for (int i = 0; i < read; i++) { diff --git a/Modules/IO/Streaming/ResourceContent.cs b/Modules/IO/Streaming/ResourceContent.cs index 293ede1b..bf0da685 100644 --- a/Modules/IO/Streaming/ResourceContent.cs +++ b/Modules/IO/Streaming/ResourceContent.cs @@ -29,7 +29,7 @@ public ResourceContent(IResource resource) #region Functionality - public async ValueTask CalculateChecksumAsync() => await Resource.CalculateChecksumAsync().ConfigureAwait(false); + public async ValueTask CalculateChecksumAsync() => await Resource.CalculateChecksumAsync(); public ValueTask WriteAsync(Stream target, uint bufferSize) => Resource.WriteAsync(target, bufferSize); diff --git a/Modules/Layouting/Provider/LayoutRouter.cs b/Modules/Layouting/Provider/LayoutRouter.cs index 1f892e87..cbba01c5 100644 --- a/Modules/Layouting/Provider/LayoutRouter.cs +++ b/Modules/Layouting/Provider/LayoutRouter.cs @@ -56,7 +56,7 @@ public LayoutRouter(IHandler parent, { request.Target.Advance(); - return await handler.HandleAsync(request).ConfigureAwait(false); + return await handler.HandleAsync(request); } } else diff --git a/Modules/Markdown/MarkdownPageProvider.cs b/Modules/Markdown/MarkdownPageProvider.cs index f180143d..2aa70afe 100644 --- a/Modules/Markdown/MarkdownPageProvider.cs +++ b/Modules/Markdown/MarkdownPageProvider.cs @@ -53,7 +53,7 @@ public MarkdownPageProvider(IHandler parent, IResource fileProvider, ContentInfo public async ValueTask HandleAsync(IRequest request) { var content = await Renderer.RenderAsync(null) - .ConfigureAwait(false); + ; var templateModel = new TemplateModel(request, this, PageInfo, Additions, content); diff --git a/Modules/Pages/Combined/CombinedPageContent.cs b/Modules/Pages/Combined/CombinedPageContent.cs index 06f7f81d..c1910c04 100644 --- a/Modules/Pages/Combined/CombinedPageContent.cs +++ b/Modules/Pages/Combined/CombinedPageContent.cs @@ -53,7 +53,7 @@ public CombinedPageContent(List fragments, ContentInfo pageInfo foreach (var fragment in Fragments) { - hash = hash * 23 + await fragment.Renderer.CalculateChecksumAsync().ConfigureAwait(false); + hash = hash * 23 + await fragment.Renderer.CalculateChecksumAsync(); hash = hash * 23 + await fragment.Model.CalculateChecksumAsync(); } diff --git a/Modules/Pages/Combined/CombinedPageProvider.cs b/Modules/Pages/Combined/CombinedPageProvider.cs index 595a7482..d0696b9d 100644 --- a/Modules/Pages/Combined/CombinedPageProvider.cs +++ b/Modules/Pages/Combined/CombinedPageProvider.cs @@ -47,7 +47,7 @@ public async ValueTask PrepareAsync() { foreach (var fragment in Fragments) { - await fragment.Renderer.PrepareAsync().ConfigureAwait(false); + await fragment.Renderer.PrepareAsync(); } } @@ -59,7 +59,7 @@ public async ValueTask PrepareAsync() foreach (var fragment in Fragments) { - contentFragments.Add(new ContentFragment(fragment.Renderer, await fragment.Model(request, this).ConfigureAwait(false))); + contentFragments.Add(new ContentFragment(fragment.Renderer, await fragment.Model(request, this))); } var content = new CombinedPageContent(contentFragments, ContentInfo, Additions, this, request); diff --git a/Modules/Pages/Rendering/PageProvider.cs b/Modules/Pages/Rendering/PageProvider.cs index 08265d8c..1db2f80e 100644 --- a/Modules/Pages/Rendering/PageProvider.cs +++ b/Modules/Pages/Rendering/PageProvider.cs @@ -58,7 +58,7 @@ protected PageProvider(IHandler parent, ModelProvider modelProvider, ContentI public async ValueTask HandleAsync(IRequest request) { - var model = await ModelProvider(request, this).ConfigureAwait(false); + var model = await ModelProvider(request, this); var content = new RenderedContent(Renderer, model, PageInfo, Additions); diff --git a/Modules/Pages/Rendering/RenderedContent.cs b/Modules/Pages/Rendering/RenderedContent.cs index e10fefad..c65ea643 100644 --- a/Modules/Pages/Rendering/RenderedContent.cs +++ b/Modules/Pages/Rendering/RenderedContent.cs @@ -54,7 +54,7 @@ public RenderedContent(IRenderer renderer, T model, ContentInfo pageInfo, Pag { ulong hash = 17; - hash = hash * 23 + await Model.CalculateChecksumAsync().ConfigureAwait(false); + hash = hash * 23 + await Model.CalculateChecksumAsync(); hash = hash * 23 + (uint)(PageInfo.Description?.GetHashCode() ?? 0); hash = hash * 23 + (uint)(PageInfo.Title?.GetHashCode() ?? 0); @@ -111,7 +111,7 @@ private async ValueTask WriteContent(Stream target) var handler = Model.Handler; - var pageContent = await Renderer.RenderAsync(Model).ConfigureAwait(false); + var pageContent = await Renderer.RenderAsync(Model); await handler.WritePageAsync(request, PageInfo, Additions, pageContent, target); } diff --git a/Modules/Placeholders/Providers/PageProvider.cs b/Modules/Placeholders/Providers/PageProvider.cs index 4b1194d8..6809e096 100644 --- a/Modules/Placeholders/Providers/PageProvider.cs +++ b/Modules/Placeholders/Providers/PageProvider.cs @@ -49,9 +49,9 @@ public PageProvider(IHandler parent, ContentInfo pageInfo, PageAdditions? additi public async ValueTask HandleAsync(IRequest request) { - var templateModel = new TemplateModel(request, this, PageInfo, Additions, await Content.GetResourceAsStringAsync().ConfigureAwait(false)); + var templateModel = new TemplateModel(request, this, PageInfo, Additions, await Content.GetResourceAsStringAsync()); - var page = await this.GetPageAsync(request, templateModel).ConfigureAwait(false); + var page = await this.GetPageAsync(request, templateModel); Modifications?.Apply(page); diff --git a/Modules/Placeholders/Providers/PlaceholderPageProvider.cs b/Modules/Placeholders/Providers/PlaceholderPageProvider.cs index 4405476f..b46806a2 100644 --- a/Modules/Placeholders/Providers/PlaceholderPageProvider.cs +++ b/Modules/Placeholders/Providers/PlaceholderPageProvider.cs @@ -55,11 +55,11 @@ public PlaceholderPageProvider(IHandler parent, IResource templateProvider, Mode var model = await ModelProvider(request, this); - var content = await renderer.RenderAsync(model).ConfigureAwait(false); + var content = await renderer.RenderAsync(model); var templateModel = new TemplateModel(request, this, PageInfo, Additions, content); - var page = await this.GetPageAsync(request, templateModel).ConfigureAwait(false); + var page = await this.GetPageAsync(request, templateModel); if (Modifications != null) { diff --git a/Modules/Reflection/ResponseProvider.cs b/Modules/Reflection/ResponseProvider.cs index eca319aa..66b0f383 100644 --- a/Modules/Reflection/ResponseProvider.cs +++ b/Modules/Reflection/ResponseProvider.cs @@ -58,7 +58,7 @@ public ResponseProvider(SerializationRegistry serialization, FormatterRegistry f { var wrapped = (IResultWrapper)result; - return await GetResponseAsync(request, handler, wrapped.Payload, (b) => wrapped.Apply(b)).ConfigureAwait(false); + return await GetResponseAsync(request, handler, wrapped.Payload, (b) => wrapped.Apply(b)); } // response returned by the method @@ -77,13 +77,13 @@ public ResponseProvider(SerializationRegistry serialization, FormatterRegistry f { return await handlerBuilder.Build(handler) .HandleAsync(request) - .ConfigureAwait(false); + ; } if (result is IHandler resultHandler) { return await resultHandler.HandleAsync(request) - .ConfigureAwait(false); + ; } // stream returned as a download @@ -119,7 +119,7 @@ public ResponseProvider(SerializationRegistry serialization, FormatterRegistry f } var serializedResult = await serializer.SerializeAsync(request, result) - .ConfigureAwait(false); + ; return serializedResult.Adjust(adjustments) .Build(); diff --git a/Modules/ReverseProxy/Provider/ClientResponseContent.cs b/Modules/ReverseProxy/Provider/ClientResponseContent.cs index 1d8884c8..ebcc49de 100644 --- a/Modules/ReverseProxy/Provider/ClientResponseContent.cs +++ b/Modules/ReverseProxy/Provider/ClientResponseContent.cs @@ -50,7 +50,7 @@ public ClientResponseContent(HttpResponseMessage message) public async ValueTask WriteAsync(Stream target, uint bufferSize) { - using var source = await Message.Content.ReadAsStreamAsync().ConfigureAwait(false); + using var source = await Message.Content.ReadAsStreamAsync(); await source.CopyPooledAsync(target, bufferSize); } diff --git a/Modules/ReverseProxy/Provider/ReverseProxyProvider.cs b/Modules/ReverseProxy/Provider/ReverseProxyProvider.cs index 6e916dd8..ae4798a4 100644 --- a/Modules/ReverseProxy/Provider/ReverseProxyProvider.cs +++ b/Modules/ReverseProxy/Provider/ReverseProxyProvider.cs @@ -80,7 +80,7 @@ public ReverseProxyProvider(IHandler parent, string upstream, TimeSpan connectTi { var req = ConfigureRequest(request); - var resp = await Client.SendAsync(req, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false); + var resp = await Client.SendAsync(req, HttpCompletionOption.ResponseHeadersRead); return GetResponse(resp, request).Build(); } diff --git a/Modules/Security/Cors/CorsPolicyHandler.cs b/Modules/Security/Cors/CorsPolicyHandler.cs index d9585106..131139ff 100644 --- a/Modules/Security/Cors/CorsPolicyHandler.cs +++ b/Modules/Security/Cors/CorsPolicyHandler.cs @@ -61,7 +61,7 @@ public CorsPolicyHandler(IHandler parent, Func contentFactor } else { - response = await Content.HandleAsync(request).ConfigureAwait(false); + response = await Content.HandleAsync(request); } if ((response is not null) && (policy is not null)) diff --git a/Modules/Security/Providers/SecureUpgradeConcern.cs b/Modules/Security/Providers/SecureUpgradeConcern.cs index 8b1ebd34..e7edd838 100644 --- a/Modules/Security/Providers/SecureUpgradeConcern.cs +++ b/Modules/Security/Providers/SecureUpgradeConcern.cs @@ -55,7 +55,7 @@ public SecureUpgradeConcern(IHandler parent, Func contentFac return await Redirect.To(GetRedirectLocation(request, endpoints)) .Build(this) .HandleAsync(request) - .ConfigureAwait(false); + ; } else if (Mode == SecureUpgrade.Allow) { @@ -68,7 +68,7 @@ public SecureUpgradeConcern(IHandler parent, Func contentFac var response = await Redirect.To(GetRedirectLocation(request, endpoints), true) .Build(this) .HandleAsync(request) - .ConfigureAwait(false); + ; response?.Headers.Add("Vary", "Upgrade-Insecure-Requests"); @@ -81,7 +81,7 @@ public SecureUpgradeConcern(IHandler parent, Func contentFac } } - return await Content.HandleAsync(request).ConfigureAwait(false); + return await Content.HandleAsync(request); } private static string GetRedirectLocation(IRequest request, List endPoints) diff --git a/Modules/Security/Providers/SnifferPreventionConcern.cs b/Modules/Security/Providers/SnifferPreventionConcern.cs index ff7c1ba9..0282938a 100644 --- a/Modules/Security/Providers/SnifferPreventionConcern.cs +++ b/Modules/Security/Providers/SnifferPreventionConcern.cs @@ -33,7 +33,7 @@ public SnifferPreventionConcern(IHandler parent, Func conten public async ValueTask HandleAsync(IRequest request) { - var content = await Content.HandleAsync(request).ConfigureAwait(false); + var content = await Content.HandleAsync(request); if (content != null) { diff --git a/Modules/Security/Providers/StrictTransportConcern.cs b/Modules/Security/Providers/StrictTransportConcern.cs index b6e525d9..8ea2f980 100644 --- a/Modules/Security/Providers/StrictTransportConcern.cs +++ b/Modules/Security/Providers/StrictTransportConcern.cs @@ -41,7 +41,7 @@ public StrictTransportConcern(IHandler parent, Func contentF public async ValueTask HandleAsync(IRequest request) { - var response = await Content.HandleAsync(request).ConfigureAwait(false); + var response = await Content.HandleAsync(request); if (response is not null) { diff --git a/Modules/SinglePageApplications/Provider/SinglePageProvider.cs b/Modules/SinglePageApplications/Provider/SinglePageProvider.cs index fc490aa6..6614a1a6 100644 --- a/Modules/SinglePageApplications/Provider/SinglePageProvider.cs +++ b/Modules/SinglePageApplications/Provider/SinglePageProvider.cs @@ -53,7 +53,7 @@ public SinglePageProvider(IHandler parent, IResourceTree tree, bool serverSideRo { if (request.Target.Ended) { - var index = await GetIndex().ConfigureAwait(false); + var index = await GetIndex(); if (index != null) { @@ -62,7 +62,7 @@ public SinglePageProvider(IHandler parent, IResourceTree tree, bool serverSideRo } else { - var result = await Resources.HandleAsync(request).ConfigureAwait(false); + var result = await Resources.HandleAsync(request); if (result == null) { diff --git a/Modules/StaticWebsites/Provider/StaticWebsiteHandler.cs b/Modules/StaticWebsites/Provider/StaticWebsiteHandler.cs index c94344fa..de3c04b1 100644 --- a/Modules/StaticWebsites/Provider/StaticWebsiteHandler.cs +++ b/Modules/StaticWebsites/Provider/StaticWebsiteHandler.cs @@ -62,7 +62,7 @@ public StaticWebsiteHandler(IHandler parent, IResourceTree tree, SitemapProvider { if (request.Target.Path.TrailingSlash) { - var (node, _) = await Tree.Find(request.Target).ConfigureAwait(false); + var (node, _) = await Tree.Find(request.Target); if (node != null) { diff --git a/Modules/Websites/Sites/WebsiteRenderer.cs b/Modules/Websites/Sites/WebsiteRenderer.cs index c2086c29..6a4f777b 100644 --- a/Modules/Websites/Sites/WebsiteRenderer.cs +++ b/Modules/Websites/Sites/WebsiteRenderer.cs @@ -47,19 +47,19 @@ public WebsiteRenderer(ITheme theme, public async ValueTask RenderAsync(TemplateModel model) { - return await Theme.Renderer.RenderAsync(await GetWebsiteModel(model).ConfigureAwait(false)); + return await Theme.Renderer.RenderAsync(await GetWebsiteModel(model)); } public async ValueTask RenderAsync(TemplateModel model, Stream target) { - await Theme.Renderer.RenderAsync(await GetWebsiteModel(model).ConfigureAwait(false), target); + await Theme.Renderer.RenderAsync(await GetWebsiteModel(model), target); } public ValueTask PrepareAsync() => Theme.Renderer.PrepareAsync(); private async ValueTask GetWebsiteModel(TemplateModel model) { - var menu = await Menu.GetMenuAsync(model.Request, model.Handler).ConfigureAwait(false); + var menu = await Menu.GetMenuAsync(model.Request, model.Handler); var themeModel = await Theme.GetModelAsync(model.Request, model.Handler); diff --git a/Modules/Websites/Sites/WebsiteRouter.cs b/Modules/Websites/Sites/WebsiteRouter.cs index afdcd5bc..bb57bc5e 100644 --- a/Modules/Websites/Sites/WebsiteRouter.cs +++ b/Modules/Websites/Sites/WebsiteRouter.cs @@ -94,7 +94,7 @@ public WebsiteRouter(IHandler parent, public async ValueTask PrepareAsync() { - await Handler.PrepareAsync().ConfigureAwait(false); + await Handler.PrepareAsync(); await Renderer.PrepareAsync(); @@ -114,22 +114,22 @@ public async ValueTask PrepareAsync() public async ValueTask RenderAsync(ErrorModel model) { - return await Theme.ErrorHandler.RenderAsync(model).ConfigureAwait(false); + return await Theme.ErrorHandler.RenderAsync(model); } public async ValueTask RenderAsync(ErrorModel model, Stream target) { - await Theme.ErrorHandler.RenderAsync(model, target).ConfigureAwait(false); + await Theme.ErrorHandler.RenderAsync(model, target); } public async ValueTask RenderAsync(TemplateModel model) { - return await Renderer.RenderAsync(model).ConfigureAwait(false); + return await Renderer.RenderAsync(model); } public async ValueTask RenderAsync(TemplateModel model, Stream target) { - await Renderer.RenderAsync(model, target).ConfigureAwait(false); + await Renderer.RenderAsync(model, target); } public IHandler? Find(string segment) diff --git a/Playground/Program.cs b/Playground/Program.cs index 335aa5f8..fab8e1b2 100644 --- a/Playground/Program.cs +++ b/Playground/Program.cs @@ -5,8 +5,8 @@ Host.Create() .Handler(Content.From(Resource.FromString("Hello World"))) - .Defaults() - .Development() - .Console() + //.Defaults() + //.Development() + //.Console() .Run();